#!/usr/bin/env -S godot --headless --script

extends SceneTree

func _init():
	print("开始移除主场景中的Camera2D2节点...")
	
	# 加载主场景
	var main_scene = load("res://scenes/main.tscn")
	if not main_scene:
		print("错误：无法加载主场景")
		quit(1)
		return
	
	var main_instance = main_scene.instantiate()
	
	# 查找Player节点
	var player = main_instance.get_node("Player")
	if not player:
		print("错误：无法找到Player节点")
		quit(1)
		return
	
	# 查找Camera2D2节点
	var camera = player.get_node("Camera2D2")
	if not camera:
		print("提示：未找到Camera2D2节点，可能已被移除")
		quit(0)
		return
	
	# 移除Camera2D2节点
	player.remove_child(camera)
	camera.queue_free()
	
	# 保存修改后的场景
	var packed_scene = PackedScene.new()
	var result = packed_scene.pack(main_instance)
	if result != OK:
		print("错误：无法打包场景")
		quit(1)
		return
	
	result = ResourceSaver.save(packed_scene, "res://scenes/main.tscn")
	if result != OK:
		print("错误：无法保存场景")
		quit(1)
		return
	
	print("成功移除Camera2D2节点并保存场景")
	quit(0) 